<template>
	<view class="tabbar-content">
		<u-popup v-model="show" mode="bottom" border-radius="14">
			<view class="popup-body">
				<view class="popup-item" @click="navNext('releaseHouse')">
					<image src="../static/image/build.png" mode=""></image>
					<view>发布房屋出租</view>
				</view>
				<view class="popup-item" @click="navNext('releaseCar')">
					<image src="../static/image/icon1.png" mode=""></image>
					<view>发布二手车出售</view>
				</view>
			</view>
		</u-popup>
		<u-tabbar v-model="tabbarCurrent" :beforeSwitch='beforeSwitch' :list="tabbarList"></u-tabbar>
	</view>
</template>

<script>
	import {
		getToken
	} from '@/utils/auth'
	export default {
		data() {
			return {
				tabbarList: [{
						iconPath: "/static/tabbar/index.png",
						selectedIconPath: "/static/tabbar/index-select.png",
						text: '首页',
						pagePath: '/pages/index/index',
						customIcon: false,
					},
					{
						iconPath: "/static/tabbar/publish.png",
						selectedIconPath: "/static/tabbar/publish.png",
						text: '发布',
						pagePath: '',
						customIcon: false,
					},
					{
						iconPath: "/static/tabbar/my.png",
						selectedIconPath: "/static/tabbar/my-select.png",
						text: '我的',
						pagePath: '/pages/mine/index',
						customIcon: false,
					},
				],
				// tabbarCurrent: 1,
				show: false
			}
		},
		props: {
			tabbarCurrent: {
				type: Number,
				default: 1
			}
		},
		methods: {
			beforeSwitch(index) {
				if (index == 1) {
					this.show = true
					return false
				}
				return true
			},
			navNext(url) {
				if (!getToken()) {
					uni.showModal({
						title: '提示',
						content: '请先登录后再进行发布操作',
						success: function(res) {
							if (res.confirm) {
								uni.reLaunch({
									url: '/pages/login/login'
								})
								let userInfo = uni.getStorageSync('userInfo')
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
					return
				}
				uni.navigateTo({
					url: `/pages/${url}/index`
				})
			},
		}
	}
</script>

<style lang="scss">
	.popup-body {
		height: 35vh;
		display: flex;
		justify-content: space-around;
		align-items: center;

		.popup-item {
			text-align: center;

			>image {
				width: 100rpx;
				height: 100rpx;
			}
		}
	}
</style>